﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TinyERP.Framework.Controls.Docking;

namespace TinyERP.Framework.Controls
{
    public class BaseForm : DockContent, IForm, ILocalizable
    {
        public bool AllowEdit { get; set; }
        public bool AllowCreate { get; set; }
        public bool AllowDelete { get; set; }
        public event CloseDialogHandler CloseDialog;
        public virtual Image GetIcon()
        {
            return null;
        }
        protected void InvokeCloseDialog()
        {
            if (CloseDialog != null)
            {
                CloseDialog(this);
            }
        }

        public virtual void RegisterShortcuts()
        {

        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            UpdateLanguage();
        }

        #region ILocalizable Members

        public virtual void UpdateLanguage()
        {
            foreach (Control control in this.Controls)
            {
                ChangeLanguageOfControl(control);
            }
        }

        #endregion
        protected void ChangeLanguageOfControl(Control control)
        {
            if (control is ILocalizable)
            {
                ((ILocalizable)control).UpdateLanguage();
            }
            if (control.Controls != null && control.Controls.Count > 0)
            {
                foreach (Control childControl in control.Controls)
                {
                    ChangeLanguageOfControl(childControl);
                }
            }
        }
        public virtual void ApplyACL(bool allowEdit, bool allowDelete, bool allowCreate)
        {
            this.AllowEdit = allowEdit;
            this.AllowCreate = allowCreate;
            this.AllowDelete = allowDelete;
        }
    }
}
